<%
all_tags=tag_cloud
show_tags=tag_cloud.sort{|a,b| b.count<=>a.count}[0..9]
hidden_class="#{type}_tag_hidden"
hidden_tags=all_tags.size != show_tags.size
%>

<% unless all_tags.blank? -%>
  <% tag_cloud all_tags, %w(popular v-popular vv-popular vvv-popular vvvv-popular) do |tag, css_class| -%>
    <% if show_tag?(tag) -%>
      <%
        hide_tag=!show_tags.include?(tag)
        tag_class="#{css_class}"
        tag_class << " #{hidden_class}" if hide_tag
        style= hide_tag ? "display:none;" : ""  #has to be set as a style rather than in CSS for javascript to work
      %>
      <%= link_for_tag tag,:type=>type,:truncate_length=>40, :class => tag_class,:style=>"#{style}" -%>

    <% end -%>
  <% end -%>

  <% if hidden_tags -%>
    <div class="expand_collapse_tags_button">
      <%
      button_images=image_tag("folds/unfold.png",:id=>"toggle_#{type}_button_down") +
        image_tag("folds/fold.png",:id=>"toggle_#{type}_button_up",:style=>"display:none;")
    %>
      <%=link_to_function( button_images) do |page|
        page.select(".#{hidden_class}").each do |el|
          el.toggle
        end

        page.toggle "toggle_#{type}_button_down"
        page.toggle "toggle_#{type}_button_up"
      end
    %>
    </div>
  <% end -%>

<% end -%>
